<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BookComment extends Model
{
    protected $fillable = ['rate', 'content', 'type', 'status', 'user_id', 'book_id', 'good_num'];

    protected $table = 'book_comments';

    public function book()
    {
        return $this->belongsTo(Book::class,'book_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id');
    }

    public function scopeStatus($query, $status)
    {
        if (!in_array($status, [1,2,3])) {
            return $query;
        }

        return $query->where('status',  $status);
    }
}
